package com.lagou.edu.factory.parser;

import com.lagou.edu.factory.BeanDefinitionParser;
import org.dom4j.Element;

import java.util.List;
import java.util.Map;

/**
 * @Author: ZLY
 * @Date: 2020/10/14 22:54
 * @Description:
 */
public class SimpleBeanDefinitionParser implements BeanDefinitionParser {
    @Override
    public void parse(List<Element> elementList, Map<String,Object> beanMap) throws IllegalAccessException, InstantiationException, ClassNotFoundException {
        for (int i = 0; i < elementList.size(); i++) {
            Element element =  elementList.get(i);
            // 处理每个bean元素，获取到该元素的id 和 class 属性
            String id = element.attributeValue("id");        // accountDao
            String clazz = element.attributeValue("class");  // com.lagou.edu.dao.impl.JdbcAccountDaoImpl
            // 通过反射技术实例化对象
            Class<?> aClass = Class.forName(clazz);
            Object o = aClass.newInstance();  // 实例化之后的对象
            // 存储到map中待用
            beanMap.put(id,o);

        }

    }
}
